/**	
 * Author : Mht
 * Desc : For 2016 RDM 
 */
package configuration;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import lombok.extern.log4j.Log4j;

/**
 * @author Mht
 * @date Jun 6, 2016
 */
@Log4j
//@Configuration
public class ExceptionConfiguraion {

	public ExceptionConfiguraion() {
		log.info("[Initialize Exception Configuration]");
	}

	@Bean
	public SimpleMappingExceptionResolver exceptionResolver() {
		SimpleMappingExceptionResolver exceptionResolver = new SimpleMappingExceptionResolver();
		exceptionResolver.setOrder(0);
		exceptionResolver.setExceptionMappings(exceptionMappings());
		exceptionResolver.setStatusCodes(statusCodeMappings());
		exceptionResolver.setWarnLogCategory("WARN");
		return exceptionResolver;
	}

	@SuppressWarnings("serial")
	Properties exceptionMappings() {

		return new Properties() {

			{
				setProperty("java.lang.Exception", "/500");
				setProperty("java.lang.Throwable", "/500");
			}
		};
	}

	@SuppressWarnings("serial")
	Properties statusCodeMappings() {

		return new Properties() {

			{
				setProperty("/500", "500");
				setProperty("/404", "404");
				setProperty("/405", "405");
			}
		};
	}
}
